package Exception;

import java.io.IOException;

/**
 * @author ZhuQi
 * @ClassName Demo
 * @Date 2022/11/22 9:49
 * @Version 1.0
 * @Description 原始异常包装成自定义异常。在web环境结合全局异常处理。能做到捕获的方法少，每次都抛出业务异常，切不丢失原异常信息
 */
public class Demo {
    public static void main(String[] args) {
        IOException ioException = new IOException("文件不存");

        ProjectException projectException = new ProjectException();
        projectException.initCause(ioException);

        try {
            exceptionHandle(projectException);
        } catch (ProjectException e) {
            e.printStackTrace();
        }
    }

    private static void exceptionHandle(ProjectException projectException) throws ProjectException {
        Throwable cause = projectException.getCause();
        System.out.println(cause.getMessage());
        System.out.println(cause.getStackTrace());
        throw projectException;
    }
}
